import { id } from "element-plus/es/locale";
import request from "./request";
import qs from "qs";

//登录返回token
export const adminLoginApi = (
  data: AdminLoginData
): PromiseRes<AdminLoginDataRes> => request.post("/login", data);

//获取当前登录用户信息
// export const getAdminInfoApi = (): Promise<ManassageResult<AdminInfoRes>> =>
//   request.get("/info");

export const getAdminInfoApi = (): PromiseRes<AdminInfoRes> =>
  request.get("/info");

//获取用户数据
export const getAdminList = (
  data: AdminListParams
): PromiseRes<{ list: {}[] }> => request.get("/admin/list", { params: data });

//修改用户信息
export const updateAdmin = (id: number, data: AdminObjItf): PromiseRes =>
  request.post("/admin/update/" + id, data);

//新增用户信息
export const newAdmin = (data: AdminObjItf): PromiseRes =>
  request.post("/admin/new/", data);

//获取所有角色
export const getRoleListAll = (): PromiseRes<RoleObjItf[]> =>
  request.get("/role/listAll");

//获取指定用户的角色
export const getAdminRoleById = (id: number): PromiseRes<RoleObjItf[]> =>
  request.get("/admin/role" + id);

//分配用户角色
// export const upadteAdminRole = (data: {
//   adminId: number;
//   roleIds: number[];
// }): PromiseRes => request.post("/admin/role/update", data);
//query方式
// export const upadteAdminRole = (data: {
//   adminId: number;
//   roleIds: string;
// }): PromiseRes => request.post("/admin/role/update", null, { params: data });
//form-data
// export const upadteAdminRole = (data: {
//   adminId: number;
//   roleIds: number[];
// }): PromiseRes =>
//   request.post("/admin/role/update", data, {
//     headers: {
//       "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
//     },
//   });
//form-data第三方库qs
export const upadteAdminRole = (data: {
  adminId: number;
  roleIds: number[];
}): PromiseRes => request.post("/admin/role/update", qs.stringify(data));

//获取首页数据
export const getAdminStat = (): PromiseRes<IndexDataItf> =>
  request.get("/admin/stat");
